package tmall.util;

/**
 * The class for paging.
 * @author Harry Chou
 * @date 2019/3/3
 */
public class Page {
    private int start;
    private int count;
    private int total;
    private String param;

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public Page(int start, int count) {
        super();
        this.start = start;
        this.count = count;
    }

    public boolean isHasPreviouse(){
        if(start==0) {
            return false;
        }
        return true;

    }
    public boolean isHasNext(){
        if(start==getLast()) {
            return false;
        }
        return true;
    }

    public int getTotalPage(){
        int totalPage;
        // the total number is a multiple of 5
        if (0 == total % count) {
            totalPage = total /count;
        }
        // the total number is a multiple of 5
        else {
            totalPage = total / count + 1;
        }

        if(0==totalPage) {
            totalPage = 1;
        }
        return totalPage;

    }

    /**
     * get the serial number of the first item in the last page
     * @return serial number
     */
    public int getLast(){
        int last;
        if (0 == total % count) {
            last = total - count;
        }
        else {
            last = total - total % count;
        }
        last = last<0?0:last;
        return last;
    }
}
